﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:modernui="clr-namespace:FirstFloor.ModernUI"
                    xmlns:controls="clr-namespace:FirstFloor.ModernUI.Windows.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/Button.xaml" />
        <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/Converters.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="controls:ModernWindow">
        <Setter Property="BackgroundContent" Value="{DynamicResource WindowBackgroundContent}" />
        <Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" />
        <Setter Property="Foreground" Value="{DynamicResource WindowText}" />
        <Setter Property="Width" Value="800" />
        <Setter Property="Height" Value="640" />
        <Setter Property="MinWidth" Value="320" />
        <Setter Property="MinHeight" Value="320" />
        <Setter Property="ResizeMode" Value="CanResizeWithGrip" />
        <Setter Property="UseLayoutRounding" Value="True" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ModernWindow">
                    <Border x:Name="WindowBorder" Margin="{Binding Source={x:Static SystemParameters.WindowNonClientFrameThickness}}" BorderThickness="1" >
                        <Border.Resources>
                            <Storyboard x:Key="BackgroundAnimation">
                                <ColorAnimation Storyboard.TargetName="WindowBorderBackground" Storyboard.TargetProperty="Color" To="{DynamicResource WindowBackgroundColor}" Duration="0:0:.6"  />
                            </Storyboard>
                        </Border.Resources>
                        <Border.Effect>
                            <DropShadowEffect/>
                        </Border.Effect>
                        <Border.Background>
                            <SolidColorBrush x:Name="WindowBorderBackground" Color="White"/>
                        </Border.Background>

                        <Grid>
                            <Border BorderBrush="{DynamicResource WindowBorder}" BorderThickness="1"  >
                                <AdornerDecorator>
                                    <Grid x:Name="LayoutRoot">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="36" />
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="15" />
                                            
                                        </Grid.RowDefinitions>

                                        <!-- window background content -->
                                        <ContentControl Grid.RowSpan="5" Content="{TemplateBinding BackgroundContent}" FontFamily="Arial Black" FontSize="16" />

                                        <!-- title blob -->
                                        <Border Grid.RowSpan="5"
                                                Background="{DynamicResource Accent}"
                                                RenderTransform="1,0,0,1,0,32"
                                                MinWidth="14" MinHeight="53"
                                                HorizontalAlignment="Right"
                                                VerticalAlignment="Top">
                                            <TextBlock Text="{TemplateBinding Title, Converter={StaticResource ToUpperConverter}}"
                                                       Foreground="White"
                                                       Margin="0,8"
                                                       Style="{DynamicResource ModernWindowTitle}"
                                                       VerticalAlignment="Center"
                                                       DataContext="{TemplateBinding IsTitleVisible}"
                                                       Visibility="{Binding Converter={StaticResource BooleanToVisibilityConverter}}">
                                                <TextBlock.LayoutTransform>
                                                    <RotateTransform Angle="-90" />
                                                </TextBlock.LayoutTransform>
                                            </TextBlock>
                                        </Border>

                                        <!-- logo (visible only when LogoData is not null) -->
                                        <Border Background="{DynamicResource Accent}" Width="36" Height="36" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,76,0"
                                                DataContext="{TemplateBinding LogoData}"
                                                Visibility="{Binding Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=inverse}">
                                            <Path Data="{Binding}" Stretch="Fill" Fill="White" Width="24" Height="24" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                        </Border>

                                        <!-- window system buttons-->
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,8,6,0" WindowChrome.IsHitTestVisibleInChrome="True">
                                            <Button Command="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}" ToolTip="{x:Static modernui:Resources.Minimize}" Style="{StaticResource SystemButton}">
                                                <Button.Content>
                                                    <Grid Width="13" Height="12" RenderTransform="1,0,0,1,0,1">
                                                        <Path Data="M0,6 L8,6 Z" Width="10" Height="9" VerticalAlignment="Center" HorizontalAlignment="Center"
                                                              Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" StrokeThickness="2"  />
                                                    </Grid>
                                                </Button.Content>
                                            </Button>
                                            <Grid Margin="1,0,1,0">
                                                <Button x:Name="Restore" Command="{Binding Source={x:Static SystemCommands.RestoreWindowCommand}}" ToolTip="{x:Static modernui:Resources.Restore}" Style="{StaticResource SystemButton}" Visibility="Collapsed" >
                                                    <Button.Content>
                                                        <Grid Width="13" Height="12" UseLayoutRounding="True" RenderTransform="1,0,0,1,.5,.5">
                                                            <Path Data="M2,0 L8,0 L8,6 M0,3 L6,3 M0,2 L6,2 L6,8 L0,8 Z" Width="10" Height="10" VerticalAlignment="Center" HorizontalAlignment="Center"
                                                                  Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" StrokeThickness="1"  />
                                                        </Grid>
                                                    </Button.Content>
                                                </Button>
                                                <Button x:Name="Maximize" Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}" ToolTip="{x:Static modernui:Resources.Maximize}" Style="{StaticResource SystemButton}" >
                                                    <Button.Content>
                                                        <Grid Width="13" Height="12">
                                                            <Path Data="M0,1 L9,1 L9,8 L0,8 Z" Width="11" Height="10" VerticalAlignment="Center" HorizontalAlignment="Center"
                                                                  Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" StrokeThickness="2"  />
                                                        </Grid>
                                                    </Button.Content>
                                                </Button>
                                            </Grid>
                                            <Button Command="{Binding Source={x:Static SystemCommands.CloseWindowCommand}}" ToolTip="{x:Static modernui:Resources.Close}" Style="{StaticResource SystemButton}" >
                                                <Button.Content>
                                                    <Grid Width="13" Height="12" RenderTransform="1,0,0,1,0,1">
                                                        <Path Data="M0,0 L8,7 M8,0 L0,7 Z" Width="10" Height="9" VerticalAlignment="Center" HorizontalAlignment="Center"
                                                              Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" StrokeThickness="1.5"  />
                                                    </Grid>
                                                </Button.Content>
                                            </Button>
                                        </StackPanel>

                                        <!-- title links -->
                                        <ItemsControl ItemsSource="{TemplateBinding TitleLinks}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,6,180,0" WindowChrome.IsHitTestVisibleInChrome="True">
                                            <ItemsControl.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <StackPanel Orientation="Horizontal" />
                                                </ItemsPanelTemplate>
                                            </ItemsControl.ItemsPanel>
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Horizontal">
                                                        <Line x:Name="Separator" X1=".5" Y1="3" X2=".5" Y2="12" Margin="7,0,5,0" Stroke="{DynamicResource SeparatorBackground}" />

                                                        <Button Content="{Binding DisplayName}"
                                                                Command="NavigationCommands.GoToPage"
                                                                CommandParameter="{Binding Source}"
                                                                CommandTarget="{Binding ElementName=ContentFrame}"
                                                                Style="{StaticResource SystemButtonLink}" />
                                                    </StackPanel>
                                                    <DataTemplate.Triggers>
                                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                                                            <Setter Property="Visibility" TargetName="Separator" Value="Collapsed"/>
                                                        </DataTrigger>
                                                    </DataTemplate.Triggers>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>

                                        <!-- main menu -->
                                        <controls:ModernMenu Grid.Row="1"
                                                             Margin="36,0,0,0"
                                                             HorizontalAlignment="Right"
                                                             SelectedSource="{Binding Source, ElementName=ContentFrame, Mode=TwoWay}"
                                                             LinkGroups="{TemplateBinding MenuLinkGroups}" />

                                        <!-- back button -->
                                        <controls:ModernButton Name="backbtn" IconData="F1 M 33,22L 33,26L 19.75,26L 27,33L 20.5,33L 11,24L 20.5,15L 27,15L 19.75,22L 33,22 Z"
                                                               Command="NavigationCommands.BrowseBack"
                                                               CommandTarget="{Binding ElementName=ContentFrame}" 
                                                               ToolTip="عودة للصفحة السابقة" 
                                                               Grid.RowSpan="2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="20,7,0,0"
                                                               WindowChrome.IsHitTestVisibleInChrome="True" EllipseDiameter="40" EllipseStrokeThickness="2" IconWidth="20" IconHeight="20" FontFamily="Arial Black" FontSize="18" Content="" FontStyle="Normal" FontWeight="Bold">
                                        </controls:ModernButton>

                                        <!-- content frame -->
                                        <controls:ModernFrame x:Name="ContentFrame" HorizontalAlignment="Right" Grid.Row="3" Grid.RowSpan="2" Margin="36,8,16,16" Source="{Binding ContentSource, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" ContentLoader="{TemplateBinding ContentLoader}"/>

                                        <!-- resize grip -->
                                        <Grid Grid.Row="4">
                                            <Path x:Name="ResizeGrip" Visibility="Collapsed" Width="14" Height="14" Margin="1" HorizontalAlignment="Right" 
                                                  Stroke="{DynamicResource WindowText}"
                                                  StrokeThickness="2"
                                                  Stretch="None"
                                                  Data="F1 M1,10 L3,10 M5,10 L7,10 M9,10 L11,10 M2,9 L2,11 M6,9 L6,11 M10,9 L10,11 M5,6 L7,6 M9,6 L11,6 M6,5 L6,7 M10,5 L10,7 M9,2 L11,2 M10,1 L10,3" ToolTip="أضغط مع السحب لتكبير النافذة أو تصغيرها" />
                                        </Grid>
                                    </Grid>
                                </AdornerDecorator>
                            </Border>
                            <Border BorderBrush="{DynamicResource WindowBorderActive}" BorderThickness="3" Visibility="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Converter={StaticResource BooleanToVisibilityConverter}}"  />
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="Maximize" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="Restore" Property="Visibility" Value="Visible" />
                            <Setter TargetName="LayoutRoot" Property="Margin" Value="7" />
                        </Trigger>
                        <Trigger Property="WindowState" Value="Normal">
                            <Setter TargetName="Maximize" Property="Visibility" Value="Visible" />
                            <Setter TargetName="Restore" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                                <Condition Property="WindowState" Value="Normal" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ResizeGrip" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome CornerRadius="15" GlassFrameThickness="15" UseAeroCaptionButtons="False" NonClientFrameEdges="None" />
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>